package com.baturu.vin.gm.dal.dao;

import com.baturu.vin.gm.dal.entity.GMSelfRuleEntity;
import com.baturu.vin.gm.dto.GMPartsDetailDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Set;

public interface PartsDetailDAO {

    @Select("<script>" +
            "SELECT group_desc,id,parts_code partsCode,body,Catalog_Code CatalogCode,series,First_Year firstYear,Last_Year lastYear,kit,`subject`,Option_P optionP,Option_N optionN,callout pictureNO,Quantity,Part_Name_CN  partNameCN,group_Code groupCode " +
            "FROM gm_epc_cd_partdetail " +
            "WHERE Catalog_Code = #{catalogCode} and Parts_Code IN " +
            "<foreach item='item' index='index' collection='partsCodeList' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<GMPartsDetailDTO> findPartsDetails(@Param("catalogCode") String catalogCode, @Param("partsCodeList") List<String> partsCodes);


    @Select("<script>" +
            "SELECT parts_code partsCode,body,Catalog_Code CatalogCode,series,First_Year firstYear,Last_Year lastYear,kit,`subject`,Option_P optionP,Option_N optionN,callout pictureNO,Quantity,Part_Name_CN  partNameCN,group_Code groupCode " +
            "FROM gm_epc_cd_partdetail " +
            "WHERE Parts_code IN " +
            "<foreach item='item' index='index' collection='partsCodeList' open='(' separator=',' close=')'>" +
            "#{item}" +
            "</foreach>" +
            "</script>")
    List<GMPartsDetailDTO> findPartsDetailsByPartsCode(@Param("partsCodeList") List<String> partsCodes);

    @Select({"SELECT DISTINCT parts_code " ,
            "FROM gm_epc_cd_partdetail " ,
            "WHERE callout IN (${callout}) ",
            "AND subject = #{subject}",
            "AND Catalog_Code = #{catalogCode}"
            })
    List<String> findPartsDetailByCallout(@Param("callout") String callout, @Param("catalogCode") String Catalog_Code, @Param("subject") String subject);

    @Select({"<script>SELECT btrPartsCode,btrPartsName,partsCode FROM gm_parts_self_rule",
            "WHERE btrPartsName in ",
            "<foreach item = 'item' collection= 'list' open ='(' separator = ',' close = ')'>",
            "#{item}",
            "</foreach>",
            "</script>",})
    List<GMSelfRuleEntity> findSelfRule(@Param("list") Set<String> btrPartsName);

    @Select({"SELECT parts_code partsCode,body,Catalog_Code CatalogCode,series,First_Year firstYear,Last_Year lastYear,kit,`subject`,Option_P optionP,Option_N optionN,callout pictureNO,Quantity,Part_Name_CN  partNameCN,group_Code groupCode,hand " +
            "FROM gm_epc_cd_partdetail WHERE subject = #{subject} AND catalog_code = #{catalog}"})
    List<GMPartsDetailDTO> queryPartsBySubject(@Param("subject") String subject, @Param("catalog") String catalog);
}
